sysdir set PERSONAL "I:\MAA2015-20 Credit and Education\stata"
do "I:\MAA2015-20 Credit and Education\stata\outreg2.ado"
do "I:\MAA2015-20 Credit and Education\stata\rdrobust.ado"
do "I:\MAA2015-20 Credit and Education\stata\rdplot.ado"

*Appendix Table B1
use "basesample_earn.dta",clear
set more off
set matsize 10000

drop if ratio_pass>0.485&ratio_pass<0.515 


forv i = 1(1)1 {
 
rdrobust loan ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableB1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

foreach y of varlist enrol ba_5yr ba_7yr{          

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableB1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableB1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
 

drop if ratio_pass>0.47&ratio_pass<0.53 

forv i = 1(1)1 {
 
rdrobust loan ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableB1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

foreach y of varlist enrol ba_5yr ba_7yr{          

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableB1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableB1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}

*Appendix Table B2
use "basesample_earn.dta",clear
set more off
set matsize 10000


forv i = 1(1)1 {
 
rdrobust loan ratio_pass if female == `i', c(0.5) h(0.10) b(0.2) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB2,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

foreach y of varlist enrol ba_5yr ba_7yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.10) b(0.2)fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB2, excel dec(2) 

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.10) b(0.2) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB2, excel dec(2) 
}
}


forv i = 1(1)1 {
 
rdrobust loan ratio_pass if female == `i', c(0.5) h(0.20) b(0.40) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB2,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

foreach y of varlist enrol ba_5yr ba_7yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.20) b(0.40) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB2, excel dec(2) 

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.20) b(0.40) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB2, excel dec(2) 
}
}


*Appendix Table B3
use "basesample_earn_08.dta",clear
set more off
set matsize 10000


forv i = 0(1)1 {
 
foreach y of varlist loan enrol ba_5yr ba_7yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.10) b(0.20) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2001-cohort2004 year2002-year2005)
outreg2 using tableB3, excel dec(2) 
 
}
}


*Appendix Table B4
use "basesample_earn.dta",clear
set more off
set matsize 10000
merge m:m snz_uid using "allow.dta"
keep if _merge==3
keep if allower==0 
drop  if year==2010&(allow2009==1|allow2010==1)
drop  if year==2011&(allow2009==1|allow2010==1|allow2011==1) 
drop  if year==2012&(allow2009==1|allow2010==1|allow2011==1|allow2012==1)
*We drop anyone who have ever received any student allowance before performance assessment

rdrobust loan ratio_pass if female == 1, c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile  provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB4 ,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

foreach y of varlist enrol ba_5yr ba_7yr {

rdrobust `y' ratio_pass if female == 1, c(0.5) h(0.15) b(0.3) fuzzy(treat) covs(age maori disable full decile  provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB4 ,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y' ratio_pass if female == 1, c(0.5) h(0.15) b(0.3) fuzzy(loan) covs(age maori disable full decile  provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using tableB4,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}

*Appendix Figure B1
use "basesample_earn_08.dta",clear
set more off
set matsize 10000

*By gender
rdplot enrol ratio_pass if female==1&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0.2(.2)1)xtitle("Pass Rates") graphregion(color(white)) title("Enrollment (Female)"))
graph save Graph "enrol_08_female.gph", replace
graph export "enrol_08_female.png", as(png) replace 

rdplot ba_5yr ratio_pass if female==1&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0.2(.2)0.8)xtitle("Pass Rates") graphregion(color(white)) title("Completion in 5 Years (Female)"))
graph save Graph "ba5_08_female.gph", replace
graph export "ba5_08_female.png", as(png) replace

rdplot ba_7yr ratio_pass if female==1&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0.2(.2)0.8)xtitle("Pass Rates") graphregion(color(white)) title("Completion in 7 Years (Female)"))
graph save Graph "ba7_08_female.gph", replace
graph export "ba7_08_female.png", as(png) replace


rdplot enrol ratio_pass if female==0&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0.2(.2)1) xtitle("Pass Rates") graphregion(color(white)) title("Enrollment (Male)"))
graph save Graph "enrol_08_male.gph", replace
graph export "enroll_08_male.png", as(png) replace 

rdplot ba_5yr ratio_pass if female==0&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0.2(.2)0.8)xtitle("Pass Rates") graphregion(color(white)) title("Completion in 5 Years (Male)"))
graph save Graph "ba5_08_male.gph", replace
graph export "ba5_08_male.png", as(png) replace

rdplot ba_7yr ratio_pass if female==0&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0.2(.2)0.8)xtitle("Pass Rates") graphregion(color(white)) title("Completion in 7 Years (Male)"))
graph save Graph "ba7_08_male.gph", replace
graph export "ba7_08_male.png", as(png) replace


*Appendix Figure B2

use "basesample_earn.dta",clear
set more off
set matsize 10000

keep if female==1

rdplot ba_post1yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white)) title("Completion, 1 Years After Assessment (Female)", size( large)))
graph save Graph "ba_post1_female.gph", replace
graph export     "ba_post1_female.png", as(png) replace

rdplot ba_post3yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white)) title("Completion, 3 Years After Assessment (Female)", size( large)))
graph save Graph "ba_post3_female.gph", replace
graph export     "ba_post3_female.png", as(png) replace

rdplot ba_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white)) title("Completion, 5 Years After Assessment (Female)", size( large)))
graph save Graph "ba_post5_female.gph", replace
graph export     "ba_post5_female.png", as(png) replace


use "basesample_earn.dta",clear
set more off
set matsize 10000

keep if female==0

rdplot ba_post1yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white)) title("Completion, 1 Years After Assessment (Male)", size( large)))
graph save Graph "ba_post1_male.gph", replace
graph export     "ba_post1_male.png", as(png) replace

rdplot ba_post3yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white)) title("Completion, 3 Years After Assessment (Male)", size( large)))
graph save Graph "ba_post3_male.gph", replace
graph export     "ba_post3_male.png", as(png) replace

rdplot ba_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 10) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white)) title("Completion, 5 Years After Assessment (Male)", size( large)))
graph save Graph "ba_post5_male.gph", replace
graph export     "ba_post5_male.png", as(png) replace



*Appendix Figure B3
use "basesample_earn.dta",clear
set more off
set matsize 10000
merge 1:1 snz_uid year using "coursecount_trimester_cross.dta"
*see codes at the end of this do file for creating "coursecount_trimester_cross.dta"
drop if _merge==2
drop _merge
gen diff_count=pass1-pass2 

replace ratio_pass=0 if ratio_pass<0.05
replace ratio_pass=0.0999 if ratio_pass>=0.1&ratio_pass<0.125

keep if year==2010

rdplot pass1 ratio_pass if female ==1,nbins(20 20) h(0.15) p(1) c(0.5) graph_options(ylabel(-1(1)4) xtitle("Pass Rates") title("Number of Courses Passed in Trimester 1 (Female)") graphregion(color(white)))
graph save Graph "pass_t1_cross_female2010.gph", replace
graph export "pass_t1_cross_female2010.png", as(png) replace

rdplot pass2 ratio_pass if female ==1,nbins(20 20) h(0.15) p(1) c(0.5) graph_options(ylabel(-1(1)4) xtitle("Pass Rates") title("Number of Courses Passed in Trimester 2 (Female)") graphregion(color(white)))
graph save Graph "pass_t2_cross_female2010.gph", replace
graph export "pass_t2_cross_female2010.png", as(png) replace

rdplot diff_count ratio_pass if female ==1,nbins(20 20) h(0.15) p(1) c(0.5) graph_options(ylabel(-1(1)4) xtitle("Pass Rates") title("Difference in Number of Courses Passed between Trimesters 1 and 2 (Female)", size(medium)) graphregion(color(white)))
graph save Graph "diff_count_cross_female2010.gph", replace
graph export "diff_count_cross_female2010.png", as(png) replace




*Appendix Figure B4
use "basesample_earn.dta",clear
set more off
set matsize 10000

keep if female==1&year==2010

rdplot ba_post3yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 8) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white))  title("Completion, 3 Years After Assessment (Female)", size( large)))
graph save Graph "ba_post3_female10.gph", replace
graph export     "ba_post3_female10.png", as(png) replace

rdplot ba_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 8) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white))  title("Completion, 5 Years After Assessment (Female)", size( large)))
graph save Graph "ba_post5_female10.gph", replace
graph export     "ba_post5_female10.png", as(png) replace

rdplot ba_post7yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7, nbins(8 8) h(0.15) p(1) c(0.5) graph_options(ylabel(0(.2).8) xtitle("Pass Rates") graphregion(color(white))  title("Completion, 7 Years After Assessment (Female)", size( large)))
graph save Graph "ba_post7_female10.gph", replace
graph export     "ba_post7_female10.png", as(png) replace




********************************************************************************
*Sample creation for "allow.dta"
/*
use "loan.dta" 
sort snz_uid year
keep snz_uid msd_sla_ann_allowance_paid_amt year
gen allow= (msd_sla_ann_allowance_paid_amt>0& msd_sla_ann_allowance_paid_amt<. )
drop msd_sla_ann_allowance_paid_amt
reshape wide allow, i(snz_uid) j(year)
save "allow.dta",replace
*/






********************************************************************************
*Sample creation for "coursecount_trimester_cross.dta"
/*
use "course_endyear.dta", clear
keep if moe_crs_qual_type_code ==3
drop if end_year<2009 
replace start_year=2009 if start_year<2009&end_year>=2009
gen end_month=month(moe_crs_end_date)
gen start_month=month(moe_crs_start_date)
gen trimester = 1 if end_month<=7&cross==0
replace trimester =2 if end_month>7&cross==0

replace trimester =1 if  start_month<=6&cross==1
replace trimester =2 if  start_month>6&cross==1
* for courses that span two calendar years, we put them in T1(T2) if it starts before (after) July
* The resutls remain nearly identicla if we simply drop these above courses.
gen pass=(moe_crs_complete_code==2)      if completion==1            
gen count=1 if completion==1   
collapse (sum)count pass,by(snz_uid snz_moe_uid start_year trimester)
rename start_year year
sort snz_uid year
compress*
replace trimester=-1 if trimester==.
drop if trimester==-1
reshape wide count pass, i(snz_uid year) j(trimester)
save "coursecount_trimester_cross.dta",replace
*/
********************************************************************************
